package cn.tedu.forwardtest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//测试   请求转发
@WebServlet("/AServlet")
public class AServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("A被执行");
        //实现请求转发想让A调用B，本质上这是服务器的动作，浏览器没变化发现不了
        //有要求!!!
        //要求：两个资源必须在同一项目中
        //getRequestDispatcher()的参数是，对方的访问方式
        //请求转发本质上就是一次请求：在A中添加请求的数据
        request.setAttribute("name","rose");
        request.getRequestDispatcher("/BServlet").forward(request,response);
    }
}
